package com.lxh.lxhcrm.model.pojos;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;
/**
 * 开发团队 ：lxh
 * 开发人员 ：蒋鑫
 * 开发时间 ：2020/1/10 15：00
 * 类的名称 ：Department
 * 类的描述 ：部门表
 */
@Entity
public class Department {
    private int departmentId;
    private String departmentName;
    private Integer higherDepartment;
    private Integer departmentLeader;


    /*部门对员工 一对多*/
    private List<Emp> deEmp;
    @OneToMany(mappedBy = "dept")
    public List<Emp> getDeEmp() {
        return deEmp;
    }
    public void setDeEmp(List<Emp> deEmp) {
        this.deEmp = deEmp;
    }

    private Integer companyId;
    //这个companyid的基本类型之前是int 会报错  改为包装类了  --李兴洋


    /*公司对部门一对多*/
    private List<Department> deptList;
    /*部门对功能类型表 多对多*/
    private List<FunctionType> funType;
    /*部门对职位 一对多*/
    private List<Position> postList;

    @OneToMany(fetch = FetchType.LAZY)
    public List<Position> getPostList() {
        return postList;
    }

    public void setPostList(List<Position> postList) {
        this.postList = postList;
    }

    @OneToMany(fetch = FetchType.LAZY)
    public List<Department> getDeptList() {
        return deptList;
    }

    public void setDeptList(List<Department> deptList) {
        this.deptList = deptList;
    }

    @ManyToMany
    @JoinTable(name="dept_funty",
            joinColumns = {
                    @JoinColumn(name="department_id")
            },inverseJoinColumns = {
            @JoinColumn(name="function_type_id")
    })
    public List<FunctionType> getFunType() {
        return funType;
    }

    public void setFunType(List<FunctionType> funType) {
        this.funType = funType;
    }

    @Id
    @Column(name = "department_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(int departmentId) {
        this.departmentId = departmentId;
    }

    @Basic
    @Column(name = "Company_id", nullable = true)
    public Integer getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Integer companyId) {
        this.companyId = companyId;
    }
    @Basic
    @Column(name = "department_name", nullable = true, length = 20)
    public String getDepartmentName() {
        return departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    @Basic
    @Column(name = "higher_department", nullable = true)
    public Integer getHigherDepartment() {
        return higherDepartment;
    }

    public void setHigherDepartment(Integer higherDepartment) {
        this.higherDepartment = higherDepartment;
    }

    @Basic
    @Column(name = "department_leader", nullable = true)
    public Integer getDepartmentLeader() {
        return departmentLeader;
    }

    public void setDepartmentLeader(Integer departmentLeader) {
        this.departmentLeader = departmentLeader;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Department that = (Department) o;
        return departmentId == that.departmentId &&
                Objects.equals(departmentName, that.departmentName) &&
                Objects.equals(higherDepartment, that.higherDepartment) &&
                Objects.equals(departmentLeader, that.departmentLeader) &&
                Objects.equals(companyId, that.companyId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(departmentId, departmentName, higherDepartment, departmentLeader,companyId);
    }
}
